﻿using Microsoft.Data.SqlClient;
using seejee_Backendium.Core.Models;
using seejee_Backendium.Data.DbContest;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace seejee_Backendium.Data.Repositores
{
    public class UserRepository
    {
        private readonly string _connectionString;

        public UserRepository(string connectionString)
        {
            _connectionString = connectionString;
        }

        public DataTable GetUserByUsername(string username)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.ConnectionString = "Server = localhost; Database = seejee_Demo01; User ID = sa; Password = 123456; TrustServerCertificate = true; Connect Timeout = 30";
                connection.Open();
                string query = "SELECT password FROM [User] WHERE username = @Username";
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.AddWithValue("@Username", username);
                    SqlDataAdapter adapter = new SqlDataAdapter(command);
                    DataTable dataTable = new DataTable();
                    adapter.Fill(dataTable);
                    return dataTable;

                }
            }
        }
    }
}
